const app = getApp();
let filter = require('../../../utils/intercept.js')
const http = require('../../../utils/http.js')

Page(filter.identityFilter({

  /**
   * 页面的初始数据
   */
  data: {
    merchant:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    http.get('/api/index/selectMerchantDetail', {id: options.id}).then(res => {
      if (res.code == 200) {
        this.setData({
          merchant: res.result
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  toMini() {
    if (!this.data.merchant.transUrl) {
      wx.showToast({
        title: '此商户暂未开通',
      })
      return;
    }
    if (this.data.merchant.transUrlType == 3) {
      wx.navigateToMiniProgram({
        appId: this.data.merchant.transUrl,
        success(res) {
          console.log(res)
        },
        fail(res) {
          console.log(res)
        }
      })
    } else {
      wx.navigateTo({
        url: '/pages/home/merchant/webindex?transUrl=' + encodeURIComponent(this.data.merchant.transUrl)
      })
    }

  },

}))
